Tutorial: List supported formats

List supported formats

In this tutorial, we will list all of the file formats supported by the current version of the library. This tutorial assumes a basic understanding of JavaScript.

This page includes examples that you can try in the developer console. Open it now by pressing ctrl + shift + C (Apple + shift + C on Mac), and clicking Console.

Currently-supported formats

You shouldn't normally deal with file formats directly. The diary objects tutorial explains how to load diaries and automatically detect formats. But it can occasionally be useful to access the list of formats. For example, your app might want to display a list of supported formats:

  1. (Please enable JavaScript to see the list of formats)

This list was generated by examining the sleepdiary variable. To see the variable itself, open the developer console by pressing ctrl + shift + C (Apple + shift + C on Mac), then type:

console.log(sleepdiary);

You can use this in your programs just like any other variable. For example, the list above was generated by this page's JavaScript.

Here are the meanings of each member in a format definition:

  • title is the user-facing title for the format
  • name is the name the code uses internally to refer to this format
  • url is a URL with more information about the format
  • logo is a URL containing an image associated with the file format
  • icon is the name of an associated icon in a common icon list (at present, all icons begin with mdi-, indicating Material Design Icons)
  • extension is the default file extension for files in this format
  • constructor is the constructor used to generate files of this format - you should not need to use this